import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '@/views/Index'
import Register from '@/views/Register'
import NotFound from '@/views/404'
import Login from '@/views/Login'
import Home from '@/views/Home'
import Infoshow from '@/views/Infoshow'
import FundList from '@/views/FundList'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/index'
  },
  {
    path: '/index',
    name: 'index',
    component: Index,
    children: [
      {
        path: '',
        component: Home
      },
      {
        path: 'home',
        name: 'home',
        component: Home
      },
      {
        path: 'infoshow',
        name: 'infoshow',
        component: Infoshow
      },
      {
        path: 'foundlist',
        name: 'foundlist',
        component: FundList
      }
    ]
  },
  {
    path: '/register',
    name: 'register',
    component: Register
  },
  {
    path: '*',
    name: '/404',
    component: NotFound
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
]



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//路由守卫
router.beforeEach((to, from, next) => {
  const isLogin = localStorage.milink ? true : false
  if (to.path == '/login' || to.path == '/register') {
    next();
  } else {
    isLogin ? next() : next("/login")
  }
})

export default router
